package com.autotest.nore.controller;

import com.autotest.nore.common.utils.PageUtils;
import com.autotest.nore.common.utils.Pager;
import com.autotest.nore.dto.DeleteRequestDTO;
import com.autotest.nore.dto.EnvironmentParamDTO;
import com.autotest.nore.request.QueryRequest;
import com.autotest.nore.service.EnvironmentParamService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/autotest/environmentParam")
public class EnvironmentParamController {

    @Autowired
    private EnvironmentParamService environmentParamService;

    @PostMapping("/list/{goPage}/{pageSize}")
    public Pager<List<EnvironmentParamDTO>> getList(@PathVariable int goPage, @PathVariable int pageSize,
                                                       @RequestBody QueryRequest request) {
        Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
        return PageUtils.setPageInfo(page, environmentParamService.getList(request.getProjectId(),request.getEnvironment()));
    }

    @PostMapping("/save")
    public void save(@RequestBody EnvironmentParamDTO environmentParamDTO) {
        environmentParamService.add(environmentParamDTO);
    }

    @PostMapping("/update")
    public void update(@RequestBody EnvironmentParamDTO environmentParamDTO) {
        environmentParamService.update(environmentParamDTO);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody DeleteRequestDTO request) {
        String id = request.getId();
        environmentParamService.delete(id);
    }





}
